package org.bigjava.user.web.controller;

import org.bigjava.bean.Posts;
import org.bigjava.common.Constant;
import org.bigjava.user.service.impl.PostsServiceImpl;
import org.bigjava.user.service.impl.TopicServiceImpl;
import org.bigjava.user.service.impl.TypesServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.PostConstruct;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import java.util.*;

@Controller
@RequestMapping("index")
public class IndexController {
    @Autowired
    TypesServiceImpl typesService;
    @Autowired
    PostsServiceImpl postsService;
    @Autowired
    TopicServiceImpl topicservice;
    @Autowired
    private ServletContext servletContext;

    //首页热门话题分页处理
    @RequestMapping("/topicHotPage")
    public void indexHotTopic(Integer startPage) {
        int sumPage = 0;//首页热门话题总页数;
        //获取总页数
        if (topicservice.totalRecord() / Constant.hotTopicPage == 0)
            //能整除就是总页数
            sumPage = topicservice.totalRecord() / Constant.hotTopicPage;
        else
            //不能整除就+1
            sumPage = topicservice.totalRecord() / Constant.hotTopicPage + 1;
        //总页数传入Application
        servletContext.setAttribute("sumPage", sumPage);
        //获取每页的数据
        List indexHotTopic = topicservice.indexHotTopic(startPage);
        //每页获取到的数据传入Application
        servletContext.setAttribute("indexHotTopic", indexHotTopic);
    }


    //首页用户个性动态分页处理
    @RequestMapping("/userPosts")
    public void indexUserPosts(){

    }
}
